home *** CD-ROM | disk | FTP | other *** search
/ Champak 43 / Vol 43.iso / games / penguin.swf / scripts / __Packages / Class / Bullet.as < prev    next >
Encoding:
Text File  |  2007-06-26  |  8.0 KB  |  312 lines

  1. class Class.Bullet extends MovieClip
  2. {
  3.    var Vg;
  4.    var V_jumpY;
  5.    var opp;
  6.    var startX;
  7.    var x;
  8.    var startY;
  9.    var y;
  10.    var landY;
  11.    var onEnterFrame;
  12.    var Vx;
  13.    var Vy;
  14.    var area;
  15.    var timer_bounce;
  16.    var mc;
  17.    var inHit = false;
  18.    var inHitObj = false;
  19.    var inStop = false;
  20.    function Bullet()
  21.    {
  22.       super();
  23.       this.Vg = _root.Vg;
  24.       this.V_jumpY = -5;
  25.    }
  26.    function init(_opp)
  27.    {
  28.       this.opp = _opp;
  29.    }
  30.    function reset()
  31.    {
  32.       this._visible = false;
  33.       this.inHit = false;
  34.       this.inHitObj = false;
  35.       this.inStop = false;
  36.    }
  37.    function jump1()
  38.    {
  39.       this.startX = this.x;
  40.       this.startY = this.y;
  41.       this.play();
  42.    }
  43.    function jump2()
  44.    {
  45.       this.landY = _root.mc.role.y + 10;
  46.       this.onEnterFrame = function()
  47.       {
  48.          this.y += this.V_jumpY;
  49.          _root.mc.make3D(this);
  50.          this.V_jumpY += this.Vg;
  51.          if(this.y >= _root.mc.role.y + 10)
  52.          {
  53.             this.y = _root.mc.role.y + 10;
  54.             delete this.onEnterFrame;
  55.          }
  56.       };
  57.    }
  58.    function hitAway(_Vx, _Vy, countDis)
  59.    {
  60.       trace("hitAway: " + _Vx + "  " + _Vy);
  61.       this._visible = true;
  62.       this.Vx = _Vx;
  63.       this.Vy = _Vy;
  64.       var _loc5_ = ExtMath.atan2D(this.Vy,this.Vx);
  65.       this._rotation = _loc5_;
  66.       var _loc4_ = _root.playControl.wind_lv;
  67.       var _loc3_ = _loc4_ * 5;
  68.       ┬º┬ºpush(this.gotoAndPlay("fly"));
  69.       if(isNaN(_loc3_))
  70.       {
  71.          _loc3_ = 0;
  72.       }
  73.       if(_loc3_ != 0)
  74.       {
  75.          this.Vx += _loc3_;
  76.       }
  77.       var dis = 0;
  78.       this.onEnterFrame = function()
  79.       {
  80.          this.x += this.Vx;
  81.          dis += this.Vx;
  82.          if(countDis != false)
  83.          {
  84.             _root.UI_mc.setDistance(int(Math.abs(dis) * 25) / 100);
  85.          }
  86.          this.y += this.Vy;
  87.          this.Vy += this.Vg;
  88.          _root.mc.make3D(this);
  89.          if(this.checkHit())
  90.          {
  91.             return undefined;
  92.          }
  93.          if(this.y >= _root.mc.role.y)
  94.          {
  95.             this.y = _root.mc.role.y;
  96.             delete this.onEnterFrame;
  97.             this.stick();
  98.          }
  99.       };
  100.    }
  101.    function bounceAway(_Vx, _Vy)
  102.    {
  103.       this._visible = true;
  104.       this.Vx = _Vx;
  105.       this.Vy = _Vy;
  106.       var _loc5_ = ExtMath.atan2D(this.Vy,this.Vx);
  107.       this._rotation = _loc5_;
  108.       var _loc4_ = _root.playControl.wind_lv;
  109.       var _loc3_ = _loc4_ * 5;
  110.       ┬º┬ºpush(this.gotoAndPlay("fly"));
  111.       if(isNaN(_loc3_))
  112.       {
  113.          _loc3_ = 0;
  114.       }
  115.       if(_loc3_ != 0)
  116.       {
  117.          this.Vx += _loc3_;
  118.       }
  119.       var dis = 0;
  120.       this.onEnterFrame = function()
  121.       {
  122.          this.x += this.Vx;
  123.          dis += this.Vx;
  124.          this.y += this.Vy;
  125.          this.Vy += this.Vg;
  126.          _root.mc.make3D(this);
  127.          if(this.y >= _root.mc.role.y)
  128.          {
  129.             this.y = _root.mc.role.y;
  130.             delete this.onEnterFrame;
  131.             this.stick();
  132.          }
  133.       };
  134.    }
  135.    function checkHit()
  136.    {
  137.       if(this.inHit)
  138.       {
  139.          return undefined;
  140.       }
  141.       if(this.inStop)
  142.       {
  143.          return undefined;
  144.       }
  145.       var _loc5_ = _global.lToG(this.area);
  146.       var _loc4_ = this.opp.area.getBounds(_root);
  147.       if(_loc5_.x > _loc4_.xMin && _loc5_.x < _loc4_.xMax + this.Vx && _loc5_.y > _loc4_.yMin && this.Vx > 0)
  148.       {
  149.          this.hit();
  150.          return true;
  151.       }
  152.       if(_loc5_.x > _loc4_.xMin + this.Vx && _loc5_.x < _loc4_.xMax && _loc5_.y > _loc4_.yMin && this.Vx < 0)
  153.       {
  154.          this.hit();
  155.          return true;
  156.       }
  157.       if(_root.mc.iceHill instanceof MovieClip)
  158.       {
  159.          this.hit_obj(_root.mc.iceHill);
  160.       }
  161.    }
  162.    function hit()
  163.    {
  164.       this.inHit = true;
  165.       var _loc4_ = _global.lToG(this);
  166.       var _loc5_ = 200;
  167.       if(this.opp.area1.hitTest(_loc4_.x,_loc4_.y,true))
  168.       {
  169.          this.opp.hit(1,1);
  170.          var _loc6_ = this.Vx / 3;
  171.          if(Math.abs(_loc6_) > 30)
  172.          {
  173.             _loc6_ = this.Vx / 5;
  174.          }
  175.          this.timer_bounce = setInterval(this,"bounce",_loc5_,_loc6_,(- this.Vy) / 2);
  176.          _root.playControl.onHit("great");
  177.       }
  178.       else if(this.opp.area2.hitTest(_loc4_.x,_loc4_.y,true))
  179.       {
  180.          this.opp.hit(2,0.7);
  181.          _loc6_ = (- this.Vx) / 3;
  182.          if(Math.abs(_loc6_) > 30)
  183.          {
  184.             _loc6_ = (- this.Vx) / 5;
  185.          }
  186.          this.timer_bounce = setInterval(this,"bounce",_loc5_,_loc6_,(- this.Vy) / 2);
  187.          _root.playControl.onHit("great");
  188.       }
  189.       else if(this.opp.area3.hitTest(_loc4_.x,_loc4_.y,true))
  190.       {
  191.          this.opp.hit(3,0.5);
  192.          _loc6_ = (- this.Vx) / 3;
  193.          if(Math.abs(_loc6_) > 30)
  194.          {
  195.             _loc6_ = (- this.Vx) / 5;
  196.          }
  197.          this.timer_bounce = setInterval(this,"bounce",_loc5_,_loc6_,(- this.Vy) / 2);
  198.          _root.playControl.onHit("good");
  199.       }
  200.       else if(this.opp.area4.hitTest(_loc4_.x,_loc4_.y,true))
  201.       {
  202.          this.opp.hit(4,0.5);
  203.          _loc6_ = this.Vx / 3;
  204.          if(Math.abs(_loc6_) > 30)
  205.          {
  206.             _loc6_ = this.Vx / 5;
  207.          }
  208.          this.timer_bounce = setInterval(this,"bounce",_loc5_,_loc6_,(- this.Vy) / 2);
  209.          _root.playControl.onHit("good");
  210.       }
  211.       else if(this.opp.area5.hitTest(_loc4_.x,_loc4_.y,true))
  212.       {
  213.          this.opp.hit(5,0.3);
  214.          _loc6_ = (- this.Vx) / 3;
  215.          if(Math.abs(_loc6_) > 30)
  216.          {
  217.             _loc6_ = (- this.Vx) / 5;
  218.          }
  219.          this.timer_bounce = setInterval(this,"bounce",_loc5_,_loc6_,(- this.Vy) / 6);
  220.          _root.playControl.onHit("good");
  221.       }
  222.       else
  223.       {
  224.          this.opp.hit(4,0.5);
  225.          _loc6_ = this.Vx / 3;
  226.          if(Math.abs(_loc6_) > 30)
  227.          {
  228.             _loc6_ = this.Vx / 5;
  229.          }
  230.          this.timer_bounce = setInterval(this,"bounce",_loc5_,_loc6_,(- this.Vy) / 2);
  231.          _root.playControl.onHit("good");
  232.       }
  233.       delete this.onEnterFrame;
  234.       this.mc.stop();
  235.    }
  236.    function hit_obj(mc)
  237.    {
  238.       if(this.inHitObj)
  239.       {
  240.          return undefined;
  241.       }
  242.       var _loc4_ = _global.lToG(this);
  243.       var _loc6_ = 50;
  244.       if(mc.area1.hitTest(_loc4_.x,_loc4_.y,true))
  245.       {
  246.          this.inHitObj = true;
  247.          trace("hit_obj11111: ");
  248.          mc.hit(1,1);
  249.          _root.soundStart("balloon_snd");
  250.          this.timer_bounce = setInterval(this,"bounce",_loc6_,this.Vx / 3,(- this.Vy) / 2);
  251.          delete this.onEnterFrame;
  252.          this.mc.stop();
  253.       }
  254.       else if(mc.area2.hitTest(_loc4_.x,_loc4_.y,true))
  255.       {
  256.          this.inHitObj = true;
  257.          trace("hit_obj22222: ");
  258.          mc.hit(1,1);
  259.          _root.soundStart("balloon_snd");
  260.          this.timer_bounce = setInterval(this,"bounce",_loc6_,(- this.Vx) / 3,(- this.Vy) / 2);
  261.          delete this.onEnterFrame;
  262.          this.mc.stop();
  263.       }
  264.    }
  265.    function bounce(bounceVx, bounceVy)
  266.    {
  267.       clearInterval(this.timer_bounce);
  268.       this.mc.play();
  269.       this.bounceAway(bounceVx,bounceVy);
  270.    }
  271.    function stick()
  272.    {
  273.       this.moveStop();
  274.    }
  275.    function slide(_Vx)
  276.    {
  277.       this.Vx = _Vx;
  278.       this.onEnterFrame = function()
  279.       {
  280.          this.x += this.Vx;
  281.          this.Vx *= 0.9;
  282.          _root.mc.make3D(this);
  283.          if(this.Vx < 1)
  284.          {
  285.             delete this.onEnterFrame;
  286.             this.moveStop();
  287.          }
  288.       };
  289.    }
  290.    function moveStop()
  291.    {
  292.       this.inStop = true;
  293.       _root.mc.addObj("bulletStick",this.x,this.y + 20,3 + int(Math.random() * 3));
  294.       this._visible = false;
  295.       this.gotoAndStop(1);
  296.       if(this.inHit != true)
  297.       {
  298.          _root.playControl.onMiss();
  299.       }
  300.       else
  301.       {
  302.          _root.playControl.onShootEnd();
  303.       }
  304.       _root.soundStart("hit2_snd");
  305.       delete this.onEnterFrame;
  306.    }
  307.    function onUnload()
  308.    {
  309.       clearInterval(this.timer_bounce);
  310.    }
  311. }
  312.